package jee.boot.common.basic.interceptor.impl;

import jee.boot.common.basic.DataEntity;
import jee.boot.common.basic.interceptor.PreUpdateInterceptor;
import jee.boot.entity.auth.Account;
import jee.boot.common.standard.AccountHandler;
import jee.boot.common.utils.SpringContextHolder;

import java.util.Date;

public class DefaultPreUpdateInterceptor implements PreUpdateInterceptor {
    /**
     * 执行前置操作
     *
     * @param entity
     */
    @Override
    public void execute(DataEntity<?> entity) {
        Account account = SpringContextHolder.getApplicationContext().getBean(AccountHandler.class).getPrincipal();
        if (account != null) {
            entity.setUpdateBy(account.shortInfo());
        }
        entity.setUpdateDate(new Date());
    }
}
